package com.example.yy.rfidreadcardtest;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    RequestQueue requestQueue;

    private EditText etUserName,etPassWord;
    private Button btLogin,btCancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        requestQueue = MyApplication.getsRequestQueue();
    }

    private void init() {
        etUserName=(EditText)findViewById(R.id.etUserName);
        etPassWord=(EditText)findViewById(R.id.etPassWord);
        btLogin=(Button)findViewById(R.id.btLogin);
        btCancel=(Button)findViewById(R.id.btCancel);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btLogin:
                String url = "";
                StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        if (s.equals("success")) {
                            Log.d("login========", "success");
                            Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                            startActivity(intent);
                        } else {
                            Toast.makeText(MainActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        Log.d("Login========","Error========");
                    }
                }

                );
                requestQueue.add(stringRequest);
                break;
            case R.id.btCancel:
                break;
        }

    }
}
